package com.zust.ysc.entity;

import lombok.Getter;
import lombok.Setter;

/**
 * @Description 统一后端返回JSON格式(形如：{"code":"0","data":{"id":1,"password":"123456","username":"倪升武"},"msg":"操作成功！"})
 * @Author Github: MatoYing
 * @Date 27/02/2023 6:48 pm
 */

@Getter
@Setter
public class JsonResult<T> {
   private T data;
   private int code;
   private String msg;

   /**
    * 若没有数据返回，默认状态码为 0，提示信息为“操作成功！”
    */
   public JsonResult() {
      this.code = 0;
      this.msg = "操作成功！";
   }

   public JsonResult(int code) {
      this.code = code;
      this.msg = "操作成功！";
   }

   /**
    * 若没有数据返回，可以人为指定状态码和提示信息
    * @param code
    * @param msg
    */
   public JsonResult(int code, String msg) {
      this.code = code;
      this.msg = msg;
   }

   /**
    * 有数据返回时，状态码为 0，默认提示信息为“操作成功！”
    * @param data
    */
   public JsonResult(T data) {
      this.data = data;
      this.code = 0;
      this.msg = "操作成功！";
   }

   /**
    * 有数据返回，状态码为 0，人为指定提示信息
    * @param data
    * @param msg
    */
   public JsonResult(T data, String msg) {
      this.data = data;
      this.code = 0;
      this.msg = msg;
   }
}
